package getRedPacket抢红包;

import java.util.Arrays;
import java.util.Random;

public class RedPacket implements Runnable{

    static int num1,num2,num3;
    static int[] packet = {0,0,num1,num2,num3};
    static int count = 0;

    public RedPacket() {
        Random random = new Random();
        packet[2] =  random.nextInt(50);
        packet[3]= random.nextInt(50);
        packet[4] = 100-packet[2]-packet[3];

        for (int i = 0; i < packet.length; i++) {
            int j = random.nextInt(5);
            int tmp = packet[i];
            packet[i] = packet[j];
            packet[j] = tmp;
        }
    }


    @Override
    public void run() {
            synchronized (Random.class){
                if(count == 5){
                    return;
                }else{
                    Thread t = Thread.currentThread();
                    System.out.println(t.getName()+"抢到了"+packet[count]+"元");
                    count++;
                }
            }
    }
}
